package com.example.food03;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.food03.strongweb_bool.HTMLtool;
import com.example.food03.strongweb_bool.ImgsaveUtils2;
import com.example.food03.web_bool.Shop;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity {
    public Button b1;
   public static String h1,shops="";
   public static String shop1_1[],shopname1_1[],shoppic1_1[]=null;
   public static int shopid1_1[]=new int[10];
    public static Gson gson =new Gson();;
    public static Shop shop;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    h1 = HTMLtool.getHtml("http://192.168.43.126:8080/foodService22/getAllShop.do");
                    shops=h1.substring(1, h1.length()-2);
                    shop1_1 = shops.split("\\},");
                    shopname1_1=shops.split("\\},");
                    shoppic1_1=shops.split("\\},");
                    for(int i = 0;i<shop1_1.length;i++){
                        System.out.print(" " + shop1_1[i]);
                        shop1_1[i]=shop1_1[i]+"}";
                        //Log.d("菜单2",shop1_1[i]);
                        shop=gson.fromJson(shop1_1[i], Shop.class);
                        shopname1_1[i]=shop.getShopname();
                        shoppic1_1[i]=shop.getPic();
                        shopid1_1[i]=shop.getShop_id();
                       // Log.d("看看看看",shop.getPic());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        b1=findViewById(R.id.button2);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity2.this,MainActivity.class);
                startActivity(intent);
                //存放店铺头像
                ImgsaveUtils2.donwloadImg(MainActivity2.this,"");
            }
        });
    }
}